package cn.kgc.gmall.mapper;

import cn.kgc.gmall.pojo.KeywordStats;
import cn.kgc.gmall.pojo.VisitorStats;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface VisitorStatsMapper {

    @Select("select is_new,sum(uv_ct) uv_ct,sum(pv_ct) pv_ct,sum(sv_ct) sv_ct,sum(uj_ct) uj_ct,sum(dur_sum) dur_sum" +
            " from visitor_stats_2022 where toYYYYMMDD(stt) = #{date} " +
            "group by is_new")
    List<VisitorStats> getVisitorStatsIsNew(Integer date);


    // 分时流量查询 新用户  根据小时进行分组

    @Select("select " +
            "sum(if(is_new = '1', visitor_stats_2022.uv_ct,0)) new_uv," +
            "sum(visitor_stats_2022.uv_ct) uv_ct," +
            "sum(pv_ct) pv_ct,toHour(stt) hr " +
            "from visitor_stats_2022 where toYYYYMMDD(stt) = #{date} " +
            "group by toHour(stt)")
    List<VisitorStats> getMidStatsGroupbyHourNewFlag(Integer date);

    /*@Select("select keyword,sum(keyword_stats_2022.ct * multiIf(" +
            "source='SEARCH',10, " +
            "source='ORDER',5, " +
            "source='CART',2, " +
            "source='CLICK',1,0 " +
            ")) ct from keyword_stats_2022 where toYYYYMMDD(stt) = #{date} " +
            "group by keyword " +
            "order by ct desc " +
            "limit #{limit}")*/
    List<KeywordStats> getKeyword(Integer date, Integer limit);
}
